import { getGetCodeByMail, getGetCodeByMobile, postAuthentication } from '@/services/api';

export default {
  namespace: 'global',
  state: {},
  effects: {
    *getCodeByMail({ payload }, { call }) {
      const response = yield call(getGetCodeByMail, payload);
      const { code, msg } = response;
      if (code === 1) {
        return Promise.resolve();
      }
      return Promise.reject(msg);
    },
    *getCodeByMobile({ payload }, { call }) {
      const response = yield call(getGetCodeByMobile, payload);
      const { code, msg } = response;
      if (code === 1) {
        return Promise.resolve();
      }
      return Promise.reject(msg);
    },
  },

  *sendAuthentication({ payload }, { call, put }) {
    const response = yield call(postAuthentication, payload);
    const { code, msg } = response;
    if (code === 1) {
      return Promise.resolve(msg);
    }
    return Promise.reject(msg);
  },
  reducers: {},
};
